<?php


class Files_mdl extends CI_Model
{
	const TB_FILES = 'tb_files';
	
	public function __construct()
	{
		parent::__construct();
	}
	
	/**
	 * 
	 * Enter description here ...
	 * @param unknown_type $page
	 * @param unknown_type $limit
	 * @param unknown_type $offset
	 * @param unknown_type $order
	 * @param unknown_type $parentid
	 */
	public function getFilesList(  $page = true,$limit = 0, $offset = 0, $order = 'DESC' ,$parentid='' )
	{
		if($page){
			
			$this->db->limit( intval( $limit ) );
			$this->db->offset( intval( $offset ) );
			if (!empty( $parentid )) {
				
				$this->db->where('parentid', $parentid);
				 
			}
			return $this->db->get(self::TB_FILES)->result_array();
			
		} else {
			
			$cate = array();
			if (!empty( $parentid )) {
				
				$this->db->where('parentid', $parentid);
				 
			}
			$cate = $this->db->get( self::TB_FILES )->result_array();
			return $cate;
			
		}
	}
	
	/**
	 * 
	 * 添加
	 * @param Array $data
	 */
	public function addFile( $data )
	{
		return $this->db->insert(self::TB_FILES,$data);
	}
	
	
	/**
	 * 
	 * 取得files数 ...
	 * @return int num
	 */
	
	public function getFilesCount($parentid = 0)
	{
		$count = 0;
		$parentid ? $this->db->where('parentid',$parentid) : '';
		$count =  $this->db->count_all_results(self::TB_FILES);

		return $count;
	}
}